﻿Imports BUS
Imports DTO
Public Class ThemLop

    Private Sub ThemLop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _Bus As New CKhoiLopBUS()
        Dim _danhsachkhoilop As New List(Of CKhoiLopDTO)
        _danhsachkhoilop = _Bus.LayDanhSachKhoiLop()
        cbbkhoilop.DataSource = _danhsachkhoilop
        cbbkhoilop.DisplayMember = "TenKhoiLop"
        cbbkhoilop.ValueMember = "MaKhoiLop"
    End Sub

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Me.Close()
    End Sub

    Private Sub btnthem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthem.Click
        Try
            Dim _Bus As New ClopBUS()
            Dim _lopdto As New CLopDTO()
            Dim _khoilop As New CKhoiLopDTO()
            _khoilop = cbbkhoilop.SelectedItem
            _lopdto.TenLop = txttenlop.Text
            _lopdto.SiSo = 0
            _lopdto.SiSoToiDa = Int32.Parse(txtsisotoida.Text)
            _lopdto.MaKhoiLop = _khoilop.MaKhoiLop

            If _Bus.KiemTraSoLuongLop(_khoilop) > 0 Then
                If _Bus.ThemLop(_lopdto) > 0 Then
                    MessageBox.Show("Them Lop Thanh Cong")
                Else
                    MessageBox.Show("Them Lop That Bai")
                End If
            Else
                MessageBox.Show(" " + _khoilop.TenKhoiLop + " Da Du Lop")
            End If
            
        Catch ex As Exception
            MessageBox.Show("Loi --> " + ex.ToString())
        End Try
        
    End Sub
End Class